package com.climber.android.lib_share.platform.qq

import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.tencent.qzone.QZone
import com.climber.android.lib_share.entity.ShareConfig
import com.climber.android.lib_share.sensor.MyShareActionListener
import com.climber.android.lib_share.sensor.ShareAction
import com.climber.android.lib_share.sensor.ShareResultCallBack
import com.mob.MobSDK

/**
 * Created by Mikes at 2020-03-19 16:25
 * QQ 好友 分享
 */
class QQZoneShare internal constructor(val shareConfig : ShareConfig, val builder: ShareResultCallBack.Builder.()->Unit): ShareAction {
    override fun shareMusic() {
    }

    override fun shareFile() {
    }

    override fun shareMiniProgram() {
    }

    // 分享纯文字
    override fun shareText() {
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_TEXT
        shareParams.title = shareConfig.title
        shareParams.titleUrl = shareConfig.titleUrl
        shareParams.text = shareConfig.text
        shareParams.site = shareConfig.site ?: ""
        shareParams.siteUrl = shareConfig.siteUrl ?: ""

        val platform = ShareSDK.getPlatform(QZone.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    // 分享图片
    override fun shareImage(){
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_IMAGE
        shareParams.title = shareConfig.title
        shareParams.titleUrl = shareConfig.titleUrl
        shareParams.text = shareConfig.text
        shareParams.site = shareConfig.site ?: ""
        shareParams.siteUrl = shareConfig.siteUrl ?: ""
        shareParams.imageUrl = shareConfig.imageUrl ?: ""
        shareParams.imagePath = shareConfig.imagePath?: ""
        shareParams.isShareTencentWeibo = false

        val platform = ShareSDK.getPlatform(QZone.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    override fun shareVideo(){
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_VIDEO
        shareParams.text = shareConfig.text
        shareParams.filePath = shareConfig.filePath ?: ""

        val platform = ShareSDK.getPlatform(QZone.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    override fun shareWebPage(){
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_WEBPAGE

        shareParams.title = shareConfig.title
        shareParams.titleUrl = shareConfig.titleUrl
        shareParams.text = shareConfig.text
        shareParams.site = shareConfig.site ?: ""
        shareParams.siteUrl = shareConfig.siteUrl ?: ""
        shareParams.imageUrl = shareConfig.imageUrl ?: ""
        shareParams.imagePath = shareConfig.imagePath?: ""

        val platform = ShareSDK.getPlatform(QZone.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }
}